/**
 *
 * @author
 *
 */
'use strict';
var __spreadArrays = (this && this.__spreadArrays) || function () {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
};
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var ne;
(function (ne) {
    var EventManager = /** @class */ (function () {
        function EventManager() {
        }
        Object.defineProperty(EventManager, "events", {
            /**
             * @private
             */
            get: function () {
                return this._events_mod;
            },
            enumerable: false,
            configurable: true
        });
        /**
         * 注册事件，初始化的时候所有的事件都被注册了
         * @param $event 模块事件
         *
         */
        EventManager.registerEvent = function (eventVo, receivedEventsHanlder) {
            if (receivedEventsHanlder === void 0) { receivedEventsHanlder = null; }
            if (eventVo === null)
                return;
            this._receivedEventsHanlder = receivedEventsHanlder;
            var eventClass = eventVo.eventClass;
            if (eventClass) {
                if (this._events_mod.get(eventClass) === undefined)
                    this._events_mod.set(eventClass, []);
                //判断是否存在代理
                var key = eventVo.eventClass;
                var events = this._events_mod.get(eventVo.eventClass);
                var find = void 0;
                for (var i = 0, l = events.length; i < l; i++) {
                    if (events[i].proxy === eventVo.proxy) {
                        find = true;
                        break;
                    }
                }
                if (!find)
                    events.push(eventVo);
            }
        };
        /**
         * 注册事件，初始化的时候所有的事件都被注册了
         * @param $event 模块事件
         *
         */
        EventManager.registerStringEvent = function (eventVo, receivedEventsHanlder) {
            if (receivedEventsHanlder === void 0) { receivedEventsHanlder = null; }
            if (eventVo === null)
                return;
            this._receivedEventsHanlder = receivedEventsHanlder;
            var eventString = eventVo.eventString;
            if (eventString) {
                if (this._events_str.get(eventString) === undefined)
                    this._events_str.set(eventString, []);
                //判断是否存在代理
                var events = this._events_str.get(eventString);
                var find = void 0;
                for (var i = 0, l = events.length; i < l; i++) {
                    if (events[i].proxy === eventVo.proxy) {
                        find = true;
                        break;
                    }
                }
                if (!find)
                    events.push(eventVo);
            }
        };
        /**
         * 某个代理发送事件
         * @param $proxy 事件代理
         * @param event 事件
         *
         */
        EventManager.dispatchModuleEvent = function (event) {
            if (!event)
                return;
            var events = this._events_mod.get(event.getClass());
            if (events) {
                for (var i = 0, l = events.length; i < l; i++) {
                    var eventVo = events[i];
                    eventVo.proxy.receivedEvents(event);
                    if (this._receivedEventsHanlder) {
                        this._receivedEventsHanlder(eventVo, event);
                    }
                }
            }
        };
        /**
         * 某个代理发送事件
         * @param $proxy 事件代理
         * @param event 事件
         *
         */
        EventManager.dispatchStringEvent = function (event, eventdata) {
            if (!event)
                return;
            var events = this._events_str.get(event);
            if (events) {
                for (var i = 0, l = events.length; i < l; i++) {
                    var eventVo = events[i];
                    eventVo.proxy.receivedStringEvents(event, eventdata);
                    if (this._receivedEventsHanlder) {
                        this._receivedEventsHanlder(eventVo, event);
                    }
                }
            }
        };
        /** save all mod messages */
        EventManager._events_mod = new Map();
        /** save all str messages */
        EventManager._events_str = new Map();
        return EventManager;
    }());
    ne.EventManager = EventManager;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var EventVo = /** @class */ (function () {
        function EventVo() {
            // eventClass
            this._id = 0;
            EventVo._uniqueID += 1;
            this._id = EventVo._uniqueID;
        }
        Object.defineProperty(EventVo.prototype, "id", {
            get: function () {
                return this._id;
            },
            enumerable: false,
            configurable: true
        });
        EventVo._uniqueID = 0;
        return EventVo;
    }());
    ne.EventVo = EventVo;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var Module = /** @class */ (function () {
        function Module() {
            /**代理实例集合*/
            this._proxyClassMap = new Map();
        }
        Module.prototype.onStart = function () { };
        /**注册代理列表*/
        Module.prototype.registerProxys = function () {
            return [];
        };
        /**
         * 获取代理,由于代理全局唯一，因此，只需要通过代理类名引用即可
         * @param $proxyClass 代理名
         * @return
         *
         */
        Module.prototype.getProxy = function ($proxyClass) {
            return this._proxyClassMap.get($proxyClass);
        };
        /**启动Proxy*/
        Module.prototype.startProxy = function () {
            this._resigerProxys = this.registerProxys();
            var _id = 0;
            for (var i = 0, l = this._resigerProxys.length; i < l; i++) {
                var proxyClass = this._resigerProxys[i];
                var _proxyInstance = new proxyClass(this);
                this._proxyClassMap.set(proxyClass, _proxyInstance);
                _proxyInstance.startEvents();
            }
        };
        return Module;
    }());
    ne.Module = Module;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var ModuleEvent = /** @class */ (function () {
        function ModuleEvent() {
        }
        /**
         * 获取类
         * @return 当前实例的类名
         *
         */
        ModuleEvent.prototype.getClass = function () {
            return this['constructor'];
        };
        return ModuleEvent;
    }());
    ne.ModuleEvent = ModuleEvent;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var ModuleManager = /** @class */ (function () {
        function ModuleManager() {
        }
        /**
         * 注册模块
         * @param $moduleClass
         *
         */
        ModuleManager.resigerModules = function ($modules) {
            this._modules = $modules;
        };
        /**启动各个模块*/
        ModuleManager.startModules = function () {
            for (var i = 0, l = this._modules.length; i < l; i++) {
                var $moduleClass = this._modules[i];
                var _instance = new $moduleClass();
                //启动所有代理
                _instance.startProxy();
                _instance.onStart();
            }
        };
        ModuleManager.registerModule = function ($module) {
            var $moduleClass = $module;
            var ins = new $moduleClass();
            ins.startProxy();
        };
        return ModuleManager;
    }());
    ne.ModuleManager = ModuleManager;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var Proxy = /** @class */ (function () {
        /**
         *
         * @param $module
         */
        function Proxy($module) {
            this._module = $module;
        }
        /**
         * 获取Proxy注册的事件列表
         * @return 返回Proxy注册的事件集
         *
         */
        Proxy.prototype.registerEvents = function () {
            return null;
        };
        /**
         * 获取Proxy注册的事件列表
         * @return 返回Proxy注册的事件集
         *
         */
        Proxy.prototype.registerStringEvents = function () {
            return null;
        };
        /**获取类*/
        Proxy.prototype.getClass = function () {
            return this['constructor'];
        };
        /**获取代理所属模块*/
        Proxy.prototype.getModule = function () {
            return this._module;
        };
        /**
         * 接收事件 子类重写此类
         * @param $event
         *
         */
        Proxy.prototype.receivedEvents = function ($event) { };
        /**
         * 接收事件 子类重写此类
         * @param $event
         *
         */
        Proxy.prototype.receivedStringEvents = function ($event, $eventdata) { };
        /**启动事件,一个代理中可能有N种事件 */
        Proxy.prototype.startEvents = function () {
            var _events_mods = this.registerEvents();
            if (_events_mods != null) {
                for (var i = 0, l = _events_mods.length; i < l; i++) {
                    var _eventVo = new ne.EventVo();
                    _eventVo.proxy = this;
                    _eventVo.eventClass = _events_mods[i];
                    ne.EventManager.registerEvent(_eventVo);
                }
            }
            var _events_str = this.registerStringEvents();
            if (_events_str != null) {
                for (var i = 0, l = _events_str.length; i < l; i++) {
                    var _eventVo = new ne.EventVo();
                    _eventVo.proxy = this;
                    _eventVo.eventString = _events_str[i];
                    ne.EventManager.registerStringEvent(_eventVo);
                }
            }
        };
        /**
         * 发送事件
         * @param $event
         *
         */
        Proxy.prototype.dispatchModuleEvent = function ($event) {
            ne.EventManager.dispatchModuleEvent($event);
        };
        /**
         * 发送事件
         * @param $event
         *
         */
        Proxy.prototype.dispatchStringEvent = function ($event, $eveutusr) {
            ne.EventManager.dispatchStringEvent($event, $eveutusr);
        };
        Proxy.prototype.dispatchNull = function (params) {
        };
        return Proxy;
    }());
    ne.Proxy = Proxy;
})(ne || (ne = {}));
var MD5 = /** @class */ (function () {
    function MD5() {
        this.hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase        */
        this.b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance   */
    }
    /*
    * These are the privates you'll usually want to call
    * They take string arguments and return either hex or base-64 encoded strings
    */
    MD5.prototype.hex_md5 = function (s) { return this.rstr2hex(this.rstr_md5(this.str2rstr_utf8(s))); }; //这个函数就行了，
    MD5.prototype.b64_md5 = function (s) { return this.rstr2b64(this.rstr_md5(this.str2rstr_utf8(s))); };
    MD5.prototype.any_md5 = function (s, e) { return this.rstr2any(this.rstr_md5(this.str2rstr_utf8(s)), e); };
    MD5.prototype.hex_hmac_md5 = function (k, d) { return this.rstr2hex(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d))); };
    MD5.prototype.b64_hmac_md5 = function (k, d) { return this.rstr2b64(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d))); };
    MD5.prototype.any_hmac_md5 = function (k, d, e) { return this.rstr2any(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d)), e); };
    /*
    * Perform a simple self-test to see if the VM is working
    */
    MD5.prototype.md5_vm_test = function () {
        return this.hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
    };
    /*
    * Calculate the MD5 of a raw string
    */
    MD5.prototype.rstr_md5 = function (s) {
        return this.binl2rstr(this.binl_md5(this.rstr2binl(s), s.length * 8));
    };
    /*
    * Calculate the HMAC-MD5, of a key and some data (raw strings)
    */
    MD5.prototype.rstr_hmac_md5 = function (key, data) {
        var bkey = this.rstr2binl(key);
        if (bkey.length > 16)
            bkey = this.binl_md5(bkey, key.length * 8);
        var ipad = Array(16), opad = Array(16);
        for (var i = 0; i < 16; i++) {
            ipad[i] = bkey[i] ^ 0x36363636;
            opad[i] = bkey[i] ^ 0x5C5C5C5C;
        }
        var hash = this.binl_md5(ipad.concat(this.rstr2binl(data)), 512 + data.length * 8);
        return this.binl2rstr(this.binl_md5(opad.concat(hash), 512 + 128));
    };
    /*
    * Convert a raw string to a hex string
    */
    MD5.prototype.rstr2hex = function (input) {
        try {
            this.hexcase;
        }
        catch (e) {
            this.hexcase = 0;
        }
        var hex_tab = this.hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
        var output = "";
        var x;
        for (var i = 0; i < input.length; i++) {
            x = input.charCodeAt(i);
            output += hex_tab.charAt((x >>> 4) & 0x0F)
                + hex_tab.charAt(x & 0x0F);
        }
        return output;
    };
    /*
    * Convert a raw string to a base-64 string
    */
    MD5.prototype.rstr2b64 = function (input) {
        try {
            this.b64pad;
        }
        catch (e) {
            this.b64pad = '';
        }
        var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        var output = "";
        var len = input.length;
        for (var i = 0; i < len; i += 3) {
            var triplet = (input.charCodeAt(i) << 16)
                | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0)
                | (i + 2 < len ? input.charCodeAt(i + 2) : 0);
            for (var j = 0; j < 4; j++) {
                if (i * 8 + j * 6 > input.length * 8)
                    output += this.b64pad;
                else
                    output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);
            }
        }
        return output;
    };
    /*
    * Convert a raw string to an arbitrary string encoding
    */
    MD5.prototype.rstr2any = function (input, encoding) {
        var divisor = encoding.length;
        var i, j, q, x, quotient;
        /* Convert to an array of 16-bit big-endian values, forming the dividend */
        var dividend = Array(Math.ceil(input.length / 2));
        for (i = 0; i < dividend.length; i++) {
            dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
        }
        /*
        * Repeatedly perform a long division. The binary array forms the dividend,
        * the length of the encoding is the divisor. Once computed, the quotient
        * forms the dividend for the next step. All remainders are stored for later
        * use.
        */
        var full_length = Math.ceil(input.length * 8 /
            (Math.log(encoding.length) / Math.log(2)));
        var remainders = Array(full_length);
        for (j = 0; j < full_length; j++) {
            quotient = Array();
            x = 0;
            for (i = 0; i < dividend.length; i++) {
                x = (x << 16) + dividend[i];
                q = Math.floor(x / divisor);
                x -= q * divisor;
                if (quotient.length > 0 || q > 0)
                    quotient[quotient.length] = q;
            }
            remainders[j] = x;
            dividend = quotient;
        }
        /* Convert the remainders to the output string */
        var output = "";
        for (i = remainders.length - 1; i >= 0; i--)
            output += encoding.charAt(remainders[i]);
        return output;
    };
    /*
    * Encode a string as utf-8.
    * For efficiency, this assumes the input is valid utf-16.
    */
    MD5.prototype.str2rstr_utf8 = function (input) {
        var output = "";
        var i = -1;
        var x, y;
        while (++i < input.length) {
            /* Decode utf-16 surrogate pairs */
            x = input.charCodeAt(i);
            y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
            if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
                x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
                i++;
            }
            /* Encode output as utf-8 */
            if (x <= 0x7F)
                output += String.fromCharCode(x);
            else if (x <= 0x7FF)
                output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F), 0x80 | (x & 0x3F));
            else if (x <= 0xFFFF)
                output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 0x80 | ((x >>> 6) & 0x3F), 0x80 | (x & 0x3F));
            else if (x <= 0x1FFFFF)
                output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 0x80 | ((x >>> 12) & 0x3F), 0x80 | ((x >>> 6) & 0x3F), 0x80 | (x & 0x3F));
        }
        return output;
    };
    /*
    * Encode a string as utf-16
    */
    MD5.prototype.str2rstr_utf16le = function (input) {
        var output = "";
        for (var i = 0; i < input.length; i++)
            output += String.fromCharCode(input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF);
        return output;
    };
    MD5.prototype.str2rstr_utf16be = function (input) {
        var output = "";
        for (var i = 0; i < input.length; i++)
            output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF);
        return output;
    };
    /*
    * Convert a raw string to an array of little-endian words
    * Characters >255 have their high-byte silently ignored.
    */
    MD5.prototype.rstr2binl = function (input) {
        var output = Array(input.length >> 2);
        for (var i = 0; i < output.length; i++)
            output[i] = 0;
        for (var i = 0; i < input.length * 8; i += 8)
            output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32);
        return output;
    };
    /*
    * Convert an array of little-endian words to a string
    */
    MD5.prototype.binl2rstr = function (input) {
        var output = "";
        for (var i = 0; i < input.length * 32; i += 8)
            output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);
        return output;
    };
    /*
    * Calculate the MD5 of an array of little-endian words, and a bit length.
    */
    MD5.prototype.binl_md5 = function (x, len) {
        /* append padding */
        x[len >> 5] |= 0x80 << ((len) % 32);
        x[(((len + 64) >>> 9) << 4) + 14] = len;
        var a = 1732584193;
        var b = -271733879;
        var c = -1732584194;
        var d = 271733878;
        for (var i = 0; i < x.length; i += 16) {
            var olda = a;
            var oldb = b;
            var oldc = c;
            var oldd = d;
            a = this.md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
            d = this.md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
            c = this.md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
            b = this.md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
            a = this.md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
            d = this.md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
            c = this.md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
            b = this.md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
            a = this.md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
            d = this.md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
            c = this.md5_ff(c, d, a, b, x[i + 10], 17, -42063);
            b = this.md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
            a = this.md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
            d = this.md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
            c = this.md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
            b = this.md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
            a = this.md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
            d = this.md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
            c = this.md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
            b = this.md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
            a = this.md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
            d = this.md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
            c = this.md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
            b = this.md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
            a = this.md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
            d = this.md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
            c = this.md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
            b = this.md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
            a = this.md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
            d = this.md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
            c = this.md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
            b = this.md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
            a = this.md5_hh(a, b, c, d, x[i + 5], 4, -378558);
            d = this.md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
            c = this.md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
            b = this.md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
            a = this.md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
            d = this.md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
            c = this.md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
            b = this.md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
            a = this.md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
            d = this.md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
            c = this.md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
            b = this.md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
            a = this.md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
            d = this.md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
            c = this.md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
            b = this.md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
            a = this.md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
            d = this.md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
            c = this.md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
            b = this.md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
            a = this.md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
            d = this.md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
            c = this.md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
            b = this.md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
            a = this.md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
            d = this.md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
            c = this.md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
            b = this.md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
            a = this.md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
            d = this.md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
            c = this.md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
            b = this.md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
            a = this.safe_add(a, olda);
            b = this.safe_add(b, oldb);
            c = this.safe_add(c, oldc);
            d = this.safe_add(d, oldd);
        }
        return [a, b, c, d];
    };
    /*
    * These privates implement the four basic operations the algorithm uses.
    */
    MD5.prototype.md5_cmn = function (q, a, b, x, s, t) {
        return this.safe_add(this.bit_rol(this.safe_add(this.safe_add(a, q), this.safe_add(x, t)), s), b);
    };
    MD5.prototype.md5_ff = function (a, b, c, d, x, s, t) {
        return this.md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
    };
    MD5.prototype.md5_gg = function (a, b, c, d, x, s, t) {
        return this.md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
    };
    MD5.prototype.md5_hh = function (a, b, c, d, x, s, t) {
        return this.md5_cmn(b ^ c ^ d, a, b, x, s, t);
    };
    MD5.prototype.md5_ii = function (a, b, c, d, x, s, t) {
        return this.md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
    };
    /*
    * Add integers, wrapping at 2^32. This uses 16-bit operations internally
    * to work around bugs in some JS interpreters.
    */
    MD5.prototype.safe_add = function (x, y) {
        var lsw = (x & 0xFFFF) + (y & 0xFFFF);
        var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
        return (msw << 16) | (lsw & 0xFFFF);
    };
    /*
    * Bitwise rotate a 32-bit number to the left.
    */
    MD5.prototype.bit_rol = function (num, cnt) {
        return (num << cnt) | (num >>> (32 - cnt));
    };
    return MD5;
}());
String.prototype.format = function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    if (args.length == 0) {
        return this;
    }
    var self = this;
    for (var i = 0; i < args.length; i++) {
        var sval = args[i];
        while (true) {
            var result = null;
            if (typeof (sval) === "number") {
                result = self.match(/(%d)|(%s)/);
                if (result) {
                    self = self.replace(/(%d)|(%s)/, sval.toString());
                    break;
                }
            }
            result = self.match(/%s/);
            if (result) {
                self = self.replace(/%s/, sval);
            }
            else {
                self += "    " + sval;
            }
            break;
        }
    }
    ;
    return self;
};
function extend(first, second) {
    var result = {};
    for (var id in first) {
        result[id] = first[id];
    }
    for (var id in second) {
        if (!result.hasOwnProperty(id)) {
            result[id] = second[id];
        }
    }
    return result;
}
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURIComponent(r[2]);
    }
    return '';
}
window["getQueryString"] = getQueryString;
var ne;
(function (ne) {
    var Singleton = /** @class */ (function () {
        function Singleton() {
        }
        Singleton.getInstance = function () {
            if (!this.instance) {
                this.instance = new this();
            }
            return this.instance;
        };
        Singleton.destory = function () {
            this.instance = null;
        };
        return Singleton;
    }());
    ne.Singleton = Singleton;
})(ne || (ne = {}));
var ne;
(function (ne) {
    /**
     * @language zh_CN
     * Base64Util 类提供用于编解码base64的方法。
     */
    var Base64Util = /** @class */ (function () {
        function Base64Util() {
        }
        /**
         * @language zh_CN
         * 编码base64。
         */
        Base64Util.encode = function (arraybuffer) {
            var bytes = new Uint8Array(arraybuffer);
            var len = bytes.length;
            var base64 = '';
            for (var i = 0; i < len; i += 3) {
                base64 += chars[bytes[i] >> 2];
                base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
                base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
                base64 += chars[bytes[i + 2] & 63];
            }
            if ((len % 3) === 2) {
                base64 = base64.substring(0, base64.length - 1) + '=';
            }
            else if (len % 3 === 1) {
                base64 = base64.substring(0, base64.length - 2) + '==';
            }
            return base64;
        };
        /**
         * @language zh_CN
         * 解码base64。
         */
        Base64Util.decode = function (base64) {
            var bufferLength = base64.length * 0.75;
            var len = base64.length;
            var p = 0;
            var encoded1 = 0;
            var encoded2 = 0;
            var encoded3 = 0;
            var encoded4 = 0;
            if (base64[base64.length - 1] === '=') {
                bufferLength--;
                if (base64[base64.length - 2] === '=') {
                    bufferLength--;
                }
            }
            var arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
            for (var i = 0; i < len; i += 4) {
                encoded1 = lookup[base64.charCodeAt(i)];
                encoded2 = lookup[base64.charCodeAt(i + 1)];
                encoded3 = lookup[base64.charCodeAt(i + 2)];
                encoded4 = lookup[base64.charCodeAt(i + 3)];
                bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
                bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
                bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
            }
            return arraybuffer;
        };
        return Base64Util;
    }());
    ne.Base64Util = Base64Util;
})(ne || (ne = {}));
/**
 * @private
 */
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
 * @private
 */
var lookup = new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
    lookup[chars.charCodeAt(i)] = i;
}
var ne;
(function (ne) {
    /**
     * Endian 类中包含一些值，它们表示用于表示多字节数字的字节顺序。
     * 字节顺序为 bigEndian（最高有效字节位于最前）或 littleEndian（最低有效字节位于最前）。
     */
    var Endian = /** @class */ (function () {
        function Endian() {
        }
        /**
         * 表示多字节数字的最低有效字节位于字节序列的最前面。
         * 十六进制数字 0x12345678 包含 4 个字节（每个字节包含 2 个十六进制数字）。最高有效字节为 0x12。最低有效字节为 0x78。（对于等效的十进制数字 305419896，最高有效数字是 3，最低有效数字是 6）。
         */
        Endian.LITTLE_ENDIAN = "littleEndian";
        /**
         * 表示多字节数字的最高有效字节位于字节序列的最前面。
         * 十六进制数字 0x12345678 包含 4 个字节（每个字节包含 2 个十六进制数字）。最高有效字节为 0x12。最低有效字节为 0x78。（对于等效的十进制数字 305419896，最高有效数字是 3，最低有效数字是 6）。
         */
        Endian.BIG_ENDIAN = "bigEndian";
        return Endian;
    }());
    ne.Endian = Endian;
    /**
     * ByteArray 类提供用于优化读取、写入以及处理二进制数据的方法和属性。
     * 注意：ByteArray 类适用于需要在字节层访问数据的高级开发人员。
     */
    var ByteArray = /** @class */ (function () {
        function ByteArray(buffer, bufferExtSize) {
            if (bufferExtSize === void 0) { bufferExtSize = 0; }
            /**
             * @private
             */
            this.bufferExtSize = 0; //Buffer expansion size
            /**
             * @private
             */
            this.EOF_byte = -1;
            /**
             * @private
             */
            this.EOF_code_point = -1;
            if (bufferExtSize < 0) {
                bufferExtSize = 0;
            }
            this.bufferExtSize = bufferExtSize;
            var bytes, wpos = 0;
            if (buffer) { //有数据，则可写字节数从字节尾开始
                var uint8 = void 0;
                if (buffer instanceof Uint8Array) {
                    uint8 = buffer;
                    wpos = buffer.length;
                }
                else {
                    wpos = buffer.byteLength;
                    uint8 = new Uint8Array(buffer);
                }
                if (bufferExtSize == 0) {
                    bytes = new Uint8Array(wpos);
                }
                else {
                    var multi = (wpos / bufferExtSize | 0) + 1;
                    bytes = new Uint8Array(multi * bufferExtSize);
                }
                bytes.set(uint8);
            }
            else {
                bytes = new Uint8Array(bufferExtSize);
            }
            this.write_position = wpos;
            this._position = 0;
            this._bytes = bytes;
            this.data = new DataView(bytes.buffer);
            this.endian = Endian.BIG_ENDIAN;
        }
        Object.defineProperty(ByteArray.prototype, "endian", {
            /**
             * 更改或读取数据的字节顺序；cex.EndianConst.BIG_ENDIAN 或 cex.EndianConst.LITTLE_ENDIAN。
             */
            get: function () {
                return this.$endian == 0 /* LITTLE_ENDIAN */ ? Endian.LITTLE_ENDIAN : Endian.BIG_ENDIAN;
            },
            set: function (value) {
                this.$endian = value == Endian.LITTLE_ENDIAN ? 0 /* LITTLE_ENDIAN */ : 1 /* BIG_ENDIAN */;
            },
            enumerable: false,
            configurable: true
        });
        /**
         * @deprecated
         */
        ByteArray.prototype.setArrayBuffer = function (buffer) {
        };
        Object.defineProperty(ByteArray.prototype, "readAvailable", {
            /**
             * 可读的剩余字节数
             *
             * @returns
             *
             * @memberOf ByteArray
             */
            get: function () {
                return this.write_position - this._position;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ByteArray.prototype, "buffer", {
            get: function () {
                return this.data.buffer.slice(0, this.write_position);
            },
            /**
             * @private
             */
            set: function (value) {
                var wpos = value.byteLength;
                var uint8 = new Uint8Array(value);
                var bufferExtSize = this.bufferExtSize;
                var bytes;
                if (bufferExtSize == 0) {
                    bytes = new Uint8Array(wpos);
                }
                else {
                    var multi = (wpos / bufferExtSize | 0) + 1;
                    bytes = new Uint8Array(multi * bufferExtSize);
                }
                bytes.set(uint8);
                this.write_position = wpos;
                this._bytes = bytes;
                this.data = new DataView(bytes.buffer);
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ByteArray.prototype, "rawBuffer", {
            get: function () {
                return this.data.buffer;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ByteArray.prototype, "bytes", {
            get: function () {
                return this._bytes;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ByteArray.prototype, "dataView", {
            /**
             * @private
             */
            get: function () {
                return this.data;
            },
            /**
             * @private
             */
            set: function (value) {
                this.buffer = value.buffer;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ByteArray.prototype, "bufferOffset", {
            /**
             * @private
             */
            get: function () {
                return this.data.byteOffset;
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ByteArray.prototype, "position", {
            /**
             * 将文件指针的当前位置（以字节为单位）移动或返回到 ByteArray 对象中。下一次调用读取方法时将在此位置开始读取，或者下一次调用写入方法时将在此位置开始写入。
             */
            get: function () {
                return this._position;
            },
            set: function (value) {
                this._position = value;
                if (value > this.write_position) {
                    this.write_position = value;
                }
            },
            enumerable: false,
            configurable: true
        });
        Object.defineProperty(ByteArray.prototype, "length", {
            /**
             * ByteArray 对象的长度（以字节为单位）。
             * 如果将长度设置为大于当前长度的值，则用零填充字节数组的右侧。
             * 如果将长度设置为小于当前长度的值，将会截断该字节数组。
             */
            get: function () {
                return this.write_position;
            },
            set: function (value) {
                this.write_position = value;
                if (this.data.byteLength > value) {
                    this._position = value;
                }
                this._validateBuffer(value);
            },
            enumerable: false,
            configurable: true
        });
        ByteArray.prototype._validateBuffer = function (value) {
            if (this.data.byteLength < value) {
                var be = this.bufferExtSize;
                var tmp = void 0;
                if (be == 0) {
                    tmp = new Uint8Array(value);
                }
                else {
                    var nLen = ((value / be >> 0) + 1) * be;
                    tmp = new Uint8Array(nLen);
                }
                tmp.set(this._bytes);
                this._bytes = tmp;
                this.data = new DataView(tmp.buffer);
            }
        };
        Object.defineProperty(ByteArray.prototype, "bytesAvailable", {
            /**
             * 可从字节数组的当前位置到数组末尾读取的数据的字节数。
             * 每次访问 ByteArray 对象时，将 bytesAvailable 属性与读取方法结合使用，以确保读取有效的数据。
             */
            get: function () {
                return this.data.byteLength - this._position;
            },
            enumerable: false,
            configurable: true
        });
        /**
         * 清除字节数组的内容，并将 length 和 position 属性重置为 0。
         */
        ByteArray.prototype.clear = function () {
            var buffer = new ArrayBuffer(this.bufferExtSize);
            this.data = new DataView(buffer);
            this._bytes = new Uint8Array(buffer);
            this._position = 0;
            this.write_position = 0;
        };
        /**
         * 从字节流中读取布尔值。读取单个字节，如果字节非零，则返回 true，否则返回 false
         * @return 如果字节不为零，则返回 true，否则返回 false
         */
        ByteArray.prototype.readBoolean = function () {
            if (this.validate(1 /* SIZE_OF_BOOLEAN */))
                return !!this._bytes[this.position++];
        };
        /**
         * 从字节流中读取带符号的字节
         * @return 介于 -128 和 127 之间的整数
         */
        ByteArray.prototype.readByte = function () {
            if (this.validate(1 /* SIZE_OF_INT8 */))
                return this.data.getInt8(this.position++);
        };
        /**
         * 从字节流中读取 length 参数指定的数据字节数。从 offset 指定的位置开始，将字节读入 bytes 参数指定的 ByteArray 对象中，并将字节写入目标 ByteArray 中
         * @param bytes 要将数据读入的 ByteArray 对象
         * @param offset bytes 中的偏移（位置），应从该位置写入读取的数据
         * @param length 要读取的字节数。默认值 0 导致读取所有可用的数据
         */
        ByteArray.prototype.readBytes = function (bytes, offset, length) {
            if (offset === void 0) { offset = 0; }
            if (length === void 0) { length = 0; }
            if (!bytes) { //由于bytes不返回，所以new新的无意义
                return;
            }
            var pos = this._position;
            var available = this.write_position - pos;
            if (available < 0) {
                return;
            }
            if (length == 0) {
                length = available;
            }
            else if (length > available) {
                return;
            }
            var position = bytes._position;
            bytes._position = 0;
            bytes.validateBuffer(offset + length);
            bytes._position = position;
            bytes._bytes.set(this._bytes.subarray(pos, pos + length), offset);
            this.position += length;
        };
        /**
         * 从字节流中读取一个 IEEE 754 双精度（64 位）浮点数
         * @return 双精度（64 位）浮点数
         */
        ByteArray.prototype.readDouble = function () {
            if (this.validate(8 /* SIZE_OF_FLOAT64 */)) {
                var value = this.data.getFloat64(this._position, this.$endian == 0 /* LITTLE_ENDIAN */);
                this.position += 8 /* SIZE_OF_FLOAT64 */;
                return value;
            }
        };
        /**
         * 从字节流中读取一个 IEEE 754 单精度（32 位）浮点数
         * @return 单精度（32 位）浮点数
         */
        ByteArray.prototype.readFloat = function () {
            if (this.validate(4 /* SIZE_OF_FLOAT32 */)) {
                var value = this.data.getFloat32(this._position, this.$endian == 0 /* LITTLE_ENDIAN */);
                this.position += 4 /* SIZE_OF_FLOAT32 */;
                return value;
            }
        };
        /**
         * 从字节流中读取一个带符号的 32 位整数
         * @return 介于 -2147483648 和 2147483647 之间的 32 位带符号整数
         */
        ByteArray.prototype.readInt = function () {
            if (this.validate(4 /* SIZE_OF_INT32 */)) {
                var value = this.data.getInt32(this._position, this.$endian == 0 /* LITTLE_ENDIAN */);
                this.position += 4 /* SIZE_OF_INT32 */;
                return value;
            }
        };
        /**
         * 从字节流中读取一个带符号的 16 位整数
         * @return 介于 -32768 和 32767 之间的 16 位带符号整数
         */
        ByteArray.prototype.readShort = function () {
            if (this.validate(2 /* SIZE_OF_INT16 */)) {
                var value = this.data.getInt16(this._position, this.$endian == 0 /* LITTLE_ENDIAN */);
                this.position += 2 /* SIZE_OF_INT16 */;
                return value;
            }
        };
        /**
         * 从字节流中读取无符号的字节
         * @return 介于 0 和 255 之间的 32 位无符号整数
         */
        ByteArray.prototype.readUnsignedByte = function () {
            if (this.validate(1 /* SIZE_OF_UINT8 */))
                return this._bytes[this.position++];
        };
        /**
         * 从字节流中读取一个无符号的 32 位整数
         * @return 介于 0 和 4294967295 之间的 32 位无符号整数
         */
        ByteArray.prototype.readUnsignedInt = function () {
            if (this.validate(4 /* SIZE_OF_UINT32 */)) {
                var value = this.data.getUint32(this._position, this.$endian == 0 /* LITTLE_ENDIAN */);
                this.position += 4 /* SIZE_OF_UINT32 */;
                return value;
            }
        };
        /**
         * 从字节流中读取一个无符号的 16 位整数
         * @return 介于 0 和 65535 之间的 16 位无符号整数
         */
        ByteArray.prototype.readUnsignedShort = function () {
            if (this.validate(2 /* SIZE_OF_UINT16 */)) {
                var value = this.data.getUint16(this._position, this.$endian == 0 /* LITTLE_ENDIAN */);
                this.position += 2 /* SIZE_OF_UINT16 */;
                return value;
            }
        };
        /**
         * 从字节流中读取一个 UTF-8 字符串。假定字符串的前缀是无符号的短整型（以字节表示长度）
         * @return UTF-8 编码的字符串
         */
        ByteArray.prototype.readUTF = function () {
            var length = this.readUnsignedShort();
            if (length > 0) {
                return this.readUTFBytes(length);
            }
            else {
                return "";
            }
        };
        /**
         * 从字节流中读取一个由 length 参数指定的 UTF-8 字节序列，并返回一个字符串
         * @param length 指明 UTF-8 字节长度的无符号短整型数
         * @return 由指定长度的 UTF-8 字节组成的字符串
         */
        ByteArray.prototype.readUTFBytes = function (length) {
            if (!this.validate(length)) {
                return;
            }
            var data = this.data;
            var bytes = new Uint8Array(data.buffer, data.byteOffset + this._position, length);
            this.position += length;
            return this.decodeUTF8(bytes);
        };
        /**
         * 写入布尔值。根据 value 参数写入单个字节。如果为 true，则写入 1，如果为 false，则写入 0
         * @param value 确定写入哪个字节的布尔值。如果该参数为 true，则该方法写入 1；如果该参数为 false，则该方法写入 0
         */
        ByteArray.prototype.writeBoolean = function (value) {
            this.validateBuffer(1 /* SIZE_OF_BOOLEAN */);
            this._bytes[this.position++] = +value;
        };
        /**
         * 在字节流中写入一个字节
         * 使用参数的低 8 位。忽略高 24 位
         * @param value 一个 32 位整数。低 8 位将被写入字节流
         */
        ByteArray.prototype.writeByte = function (value) {
            this.validateBuffer(1 /* SIZE_OF_INT8 */);
            this._bytes[this.position++] = value & 0xff;
        };
        /**
         * 将指定字节数组 bytes（起始偏移量为 offset，从零开始的索引）中包含 length 个字节的字节序列写入字节流
         * 如果省略 length 参数，则使用默认长度 0；该方法将从 offset 开始写入整个缓冲区。如果还省略了 offset 参数，则写入整个缓冲区
         * 如果 offset 或 length 超出范围，它们将被锁定到 bytes 数组的开头和结尾
         * @param bytes ByteArray 对象
         * @param offset 从 0 开始的索引，表示在数组中开始写入的位置
         * @param length 一个无符号整数，表示在缓冲区中的写入范围
         */
        ByteArray.prototype.writeBytes = function (bytes, offset, length) {
            if (offset === void 0) { offset = 0; }
            if (length === void 0) { length = 0; }
            var writeLength;
            if (offset < 0) {
                return;
            }
            if (length < 0) {
                return;
            }
            else if (length == 0) {
                writeLength = bytes.length - offset;
            }
            else {
                writeLength = Math.min(bytes.length - offset, length);
            }
            if (writeLength > 0) {
                this.validateBuffer(writeLength);
                this._bytes.set(bytes._bytes.subarray(offset, offset + writeLength), this._position);
                this.position = this._position + writeLength;
            }
        };
        /**
         * 在字节流中写入一个 IEEE 754 双精度（64 位）浮点数
         * @param value 双精度（64 位）浮点数
         */
        ByteArray.prototype.writeDouble = function (value) {
            this.validateBuffer(8 /* SIZE_OF_FLOAT64 */);
            this.data.setFloat64(this._position, value, this.$endian == 0 /* LITTLE_ENDIAN */);
            this.position += 8 /* SIZE_OF_FLOAT64 */;
        };
        /**
         * 在字节流中写入一个 IEEE 754 单精度（32 位）浮点数
         * @param value 单精度（32 位）浮点数
         */
        ByteArray.prototype.writeFloat = function (value) {
            this.validateBuffer(4 /* SIZE_OF_FLOAT32 */);
            this.data.setFloat32(this._position, value, this.$endian == 0 /* LITTLE_ENDIAN */);
            this.position += 4 /* SIZE_OF_FLOAT32 */;
        };
        /**
         * 在字节流中写入一个带符号的 32 位整数
         * @param value 要写入字节流的整数
         */
        ByteArray.prototype.writeInt = function (value) {
            this.validateBuffer(4 /* SIZE_OF_INT32 */);
            this.data.setInt32(this._position, value, this.$endian == 0 /* LITTLE_ENDIAN */);
            this.position += 4 /* SIZE_OF_INT32 */;
        };
        /**
         * 在字节流中写入一个 16 位整数。使用参数的低 16 位。忽略高 16 位
         * @param value 32 位整数，该整数的低 16 位将被写入字节流
         */
        ByteArray.prototype.writeShort = function (value) {
            this.validateBuffer(2 /* SIZE_OF_INT16 */);
            this.data.setInt16(this._position, value, this.$endian == 0 /* LITTLE_ENDIAN */);
            this.position += 2 /* SIZE_OF_INT16 */;
        };
        /**
         * 在字节流中写入一个无符号的 32 位整数
         * @param value 要写入字节流的无符号整数
         */
        ByteArray.prototype.writeUnsignedInt = function (value) {
            this.validateBuffer(4 /* SIZE_OF_UINT32 */);
            this.data.setUint32(this._position, value, this.$endian == 0 /* LITTLE_ENDIAN */);
            this.position += 4 /* SIZE_OF_UINT32 */;
        };
        /**
         * 在字节流中写入一个无符号的 16 位整数
         * @param value 要写入字节流的无符号整数
         */
        ByteArray.prototype.writeUnsignedShort = function (value) {
            this.validateBuffer(2 /* SIZE_OF_UINT16 */);
            this.data.setUint16(this._position, value, this.$endian == 0 /* LITTLE_ENDIAN */);
            this.position += 2 /* SIZE_OF_UINT16 */;
        };
        /**
         * 将 UTF-8 字符串写入字节流。先写入以字节表示的 UTF-8 字符串长度（作为 16 位整数），然后写入表示字符串字符的字节
         * @param value 要写入的字符串值
         */
        ByteArray.prototype.writeUTF = function (value) {
            var utf8bytes = this.encodeUTF8(value);
            var length = utf8bytes.length;
            this.validateBuffer(2 /* SIZE_OF_UINT16 */ + length);
            this.data.setUint16(this._position, length, this.$endian == 0 /* LITTLE_ENDIAN */);
            this.position += 2 /* SIZE_OF_UINT16 */;
            this._writeUint8Array(utf8bytes, false);
        };
        /**
         * 将 UTF-8 字符串写入字节流。类似于 writeUTF() 方法，但 writeUTFBytes() 不使用 16 位长度的词为字符串添加前缀
         * @param value 要写入的字符串值
         */
        ByteArray.prototype.writeUTFBytes = function (value) {
            this._writeUint8Array(this.encodeUTF8(value));
        };
        /**
         * @returns
         */
        ByteArray.prototype.toString = function () {
            return "[ByteArray] length:" + this.length + ", bytesAvailable:" + this.bytesAvailable;
        };
        /**
         * @private
         * 将 Uint8Array 写入字节流
         * @param bytes 要写入的Uint8Array
         * @param validateBuffer
         */
        ByteArray.prototype._writeUint8Array = function (bytes, validateBuffer) {
            if (validateBuffer === void 0) { validateBuffer = true; }
            var pos = this._position;
            var npos = pos + bytes.length;
            if (validateBuffer) {
                this.validateBuffer(npos);
            }
            this.bytes.set(bytes, pos);
            this.position = npos;
        };
        /**
         * @param len
         * @returns
         */
        ByteArray.prototype.validate = function (len) {
            var bl = this._bytes.length;
            if (bl > 0 && this._position + len <= bl) {
                return true;
            }
            else {
            }
        };
        /**********************/
        /*  PRIVATE METHODS   */
        /**********************/
        /**
         * @private
         * @param len
         * @param needReplace
         */
        ByteArray.prototype.validateBuffer = function (len) {
            this.write_position = len > this.write_position ? len : this.write_position;
            len += this._position;
            this._validateBuffer(len);
        };
        /**
         * @private
         * UTF-8 Encoding/Decoding
         */
        ByteArray.prototype.encodeUTF8 = function (str) {
            var pos = 0;
            var codePoints = this.stringToCodePoints(str);
            var outputBytes = [];
            while (codePoints.length > pos) {
                var code_point = codePoints[pos++];
                if (this.inRange(code_point, 0xD800, 0xDFFF)) {
                    this.encoderError(code_point);
                }
                else if (this.inRange(code_point, 0x0000, 0x007f)) {
                    outputBytes.push(code_point);
                }
                else {
                    var count = void 0, offset = void 0;
                    if (this.inRange(code_point, 0x0080, 0x07FF)) {
                        count = 1;
                        offset = 0xC0;
                    }
                    else if (this.inRange(code_point, 0x0800, 0xFFFF)) {
                        count = 2;
                        offset = 0xE0;
                    }
                    else if (this.inRange(code_point, 0x10000, 0x10FFFF)) {
                        count = 3;
                        offset = 0xF0;
                    }
                    outputBytes.push(this.div(code_point, Math.pow(64, count)) + offset);
                    while (count > 0) {
                        var temp = this.div(code_point, Math.pow(64, count - 1));
                        outputBytes.push(0x80 + (temp % 64));
                        count -= 1;
                    }
                }
            }
            return new Uint8Array(outputBytes);
        };
        /**
         * @private
         *
         * @param data
         * @returns
         */
        ByteArray.prototype.decodeUTF8 = function (data) {
            var fatal = false;
            var pos = 0;
            var result = "";
            var code_point;
            var utf8_code_point = 0;
            var utf8_bytes_needed = 0;
            var utf8_bytes_seen = 0;
            var utf8_lower_boundary = 0;
            while (data.length > pos) {
                var _byte = data[pos++];
                if (_byte == this.EOF_byte) {
                    if (utf8_bytes_needed != 0) {
                        code_point = this.decoderError(fatal);
                    }
                    else {
                        code_point = this.EOF_code_point;
                    }
                }
                else {
                    if (utf8_bytes_needed == 0) {
                        if (this.inRange(_byte, 0x00, 0x7F)) {
                            code_point = _byte;
                        }
                        else {
                            if (this.inRange(_byte, 0xC2, 0xDF)) {
                                utf8_bytes_needed = 1;
                                utf8_lower_boundary = 0x80;
                                utf8_code_point = _byte - 0xC0;
                            }
                            else if (this.inRange(_byte, 0xE0, 0xEF)) {
                                utf8_bytes_needed = 2;
                                utf8_lower_boundary = 0x800;
                                utf8_code_point = _byte - 0xE0;
                            }
                            else if (this.inRange(_byte, 0xF0, 0xF4)) {
                                utf8_bytes_needed = 3;
                                utf8_lower_boundary = 0x10000;
                                utf8_code_point = _byte - 0xF0;
                            }
                            else {
                                this.decoderError(fatal);
                            }
                            utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed);
                            code_point = null;
                        }
                    }
                    else if (!this.inRange(_byte, 0x80, 0xBF)) {
                        utf8_code_point = 0;
                        utf8_bytes_needed = 0;
                        utf8_bytes_seen = 0;
                        utf8_lower_boundary = 0;
                        pos--;
                        code_point = this.decoderError(fatal, _byte);
                    }
                    else {
                        utf8_bytes_seen += 1;
                        utf8_code_point = utf8_code_point + (_byte - 0x80) * Math.pow(64, utf8_bytes_needed - utf8_bytes_seen);
                        if (utf8_bytes_seen !== utf8_bytes_needed) {
                            code_point = null;
                        }
                        else {
                            var cp = utf8_code_point;
                            var lower_boundary = utf8_lower_boundary;
                            utf8_code_point = 0;
                            utf8_bytes_needed = 0;
                            utf8_bytes_seen = 0;
                            utf8_lower_boundary = 0;
                            if (this.inRange(cp, lower_boundary, 0x10FFFF) && !this.inRange(cp, 0xD800, 0xDFFF)) {
                                code_point = cp;
                            }
                            else {
                                code_point = this.decoderError(fatal, _byte);
                            }
                        }
                    }
                }
                //Decode string
                if (code_point !== null && code_point !== this.EOF_code_point) {
                    if (code_point <= 0xFFFF) {
                        if (code_point > 0)
                            result += String.fromCharCode(code_point);
                    }
                    else {
                        code_point -= 0x10000;
                        result += String.fromCharCode(0xD800 + ((code_point >> 10) & 0x3ff));
                        result += String.fromCharCode(0xDC00 + (code_point & 0x3ff));
                    }
                }
            }
            return result;
        };
        /**
         * @private
         *
         * @param code_point
         */
        ByteArray.prototype.encoderError = function (code_point) {
        };
        /**
         * @private
         *
         * @param fatal
         * @param opt_code_point
         * @returns
         */
        ByteArray.prototype.decoderError = function (fatal, opt_code_point) {
            if (fatal) {
            }
            return opt_code_point || 0xFFFD;
        };
        /**
         * @private
         *
         * @param a
         * @param min
         * @param max
         */
        ByteArray.prototype.inRange = function (a, min, max) {
            return min <= a && a <= max;
        };
        /**
         * @private
         *
         * @param n
         * @param d
         */
        ByteArray.prototype.div = function (n, d) {
            return Math.floor(n / d);
        };
        /**
         * @private
         *
         * @param string
         */
        ByteArray.prototype.stringToCodePoints = function (string) {
            /** @type {Array.<number>} */
            var cps = [];
            // Based on http://www.w3.org/TR/WebIDL/#idl-DOMString
            var i = 0, n = string.length;
            while (i < string.length) {
                var c = string.charCodeAt(i);
                if (!this.inRange(c, 0xD800, 0xDFFF)) {
                    cps.push(c);
                }
                else if (this.inRange(c, 0xDC00, 0xDFFF)) {
                    cps.push(0xFFFD);
                }
                else { // (inRange(c, 0xD800, 0xDBFF))
                    if (i == n - 1) {
                        cps.push(0xFFFD);
                    }
                    else {
                        var d = string.charCodeAt(i + 1);
                        if (this.inRange(d, 0xDC00, 0xDFFF)) {
                            var a = c & 0x3FF;
                            var b = d & 0x3FF;
                            i += 1;
                            cps.push(0x10000 + (a << 10) + b);
                        }
                        else {
                            cps.push(0xFFFD);
                        }
                    }
                }
                i += 1;
            }
            return cps;
        };
        return ByteArray;
    }());
    ne.ByteArray = ByteArray;
})(ne || (ne = {}));
var ne;
(function (ne) {
    /**
     * @private
     * 哈希计数
     */
    ne.$hashCount = 1;
    /**
     * cex顶级对象。框架内所有对象的基类，为对象实例提供唯一的hashCode值。
     */
    var HashObject = /** @class */ (function () {
        /**
         * 创建一个 HashObject 对象
         */
        function HashObject() {
            this.$hashCode = ne.$hashCount++;
        }
        Object.defineProperty(HashObject.prototype, "hashCode", {
            /**
             * 返回此对象唯一的哈希值,用于唯一确定一个对象。hashCode为大于等于1的整数。
             */
            get: function () {
                return this.$hashCode;
            },
            enumerable: false,
            configurable: true
        });
        return HashObject;
    }());
    ne.HashObject = HashObject;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var Convert = /** @class */ (function () {
        function Convert() {
        }
        /**
         * 比较当前版本与目标版本大小：
         * 当前版本>目标版本  1
         * 当前版本<目标版本 -1
         * 当前版本=目标版本  0
         * */
        Convert.compareVersion = function (targetVersion) {
            return -1;
        };
        return Convert;
    }());
    ne.Convert = Convert;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var ELOGLEVEL;
    (function (ELOGLEVEL) {
        ELOGLEVEL[ELOGLEVEL["CRITICAL"] = 50] = "CRITICAL";
        ELOGLEVEL[ELOGLEVEL["ERROR"] = 40] = "ERROR";
        ELOGLEVEL[ELOGLEVEL["WARNING"] = 30] = "WARNING";
        ELOGLEVEL[ELOGLEVEL["INFO"] = 20] = "INFO";
        ELOGLEVEL[ELOGLEVEL["DEBUG"] = 10] = "DEBUG";
        ELOGLEVEL[ELOGLEVEL["NOTSET"] = 0] = "NOTSET";
    })(ELOGLEVEL = ne.ELOGLEVEL || (ne.ELOGLEVEL = {}));
    var Logger = /** @class */ (function () {
        /**
         * Creates an instance of Logger.
         * @param {string} stag
         * @memberof Logger
         */
        function Logger(stag) {
            this._tag = stag;
            this._handlers = [];
            this._loglevel = ELOGLEVEL.DEBUG;
        }
        /**
         * 添加handler队形用于输出
         * @param  objhandler
         * @memberof Logger
         */
        Logger.prototype.addHandler = function (objhandler) {
            this._handlers.push(objhandler);
        };
        /**
         * 设置Logger的输出level等级
         *
         * @param {LOGLEVEL} lv
         * @memberof Logger
         */
        Logger.prototype.setLogLevel = function (nlv) {
            this._loglevel = nlv;
        };
        /**
         * notset等级的输出
         *
         * @param {string} sout
         * @memberof Logger
         */
        Logger.prototype.notset = function (sfmt) {
            var sout = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                sout[_i - 1] = arguments[_i];
            }
            this.log.apply(this, __spreadArrays([ELOGLEVEL.NOTSET, sfmt], sout));
        };
        /**
         * info等级的输出
         *
         * @param {string} sout
         * @memberof Logger
         */
        Logger.prototype.info = function (sfmt) {
            var sout = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                sout[_i - 1] = arguments[_i];
            }
            this.log.apply(this, __spreadArrays([ELOGLEVEL.INFO, sfmt], sout));
        };
        /**
         * debug等级的输出
         *
         * @param {string} sout
         * @memberof Logger
         */
        Logger.prototype.debug = function (sfmt) {
            var sout = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                sout[_i - 1] = arguments[_i];
            }
            this.log.apply(this, __spreadArrays([ELOGLEVEL.DEBUG, sfmt], sout));
        };
        /**
         * acritical等级的输出
         *
         * @param {string} sout
         * @memberof Logger
         */
        Logger.prototype.critical = function (sfmt) {
            var sout = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                sout[_i - 1] = arguments[_i];
            }
            this.log.apply(this, __spreadArrays([ELOGLEVEL.CRITICAL, sfmt], sout));
        };
        /**
         * error等级的输出
         *
         * @param {string} sout
         * @memberof Logger
         */
        Logger.prototype.error = function (sfmt) {
            var sout = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                sout[_i - 1] = arguments[_i];
            }
            this.log.apply(this, __spreadArrays([ELOGLEVEL.ERROR, sfmt], sout));
        };
        /**
         * warning等级的输出
         *
         * @param {string} sout
         * @memberof Logger
         */
        Logger.prototype.warning = function (sfmt) {
            var sout = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                sout[_i - 1] = arguments[_i];
            }
            this.log.apply(this, __spreadArrays([ELOGLEVEL.WARNING, sfmt], sout));
        };
        Logger.prototype.log = function (nlv, sfmt) {
            var sout = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                sout[_i - 2] = arguments[_i];
            }
            var self = this;
            this._handlers.forEach(function (objandler) {
                if (self._loglevel <= nlv) {
                    objandler.emit.apply(objandler, __spreadArrays([nlv, sfmt], sout));
                }
            });
        };
        return Logger;
    }());
    ne.Logger = Logger;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var BaseHandler = /** @class */ (function () {
        function BaseHandler(startime, gettime) {
            this._fmtstr = ""; //格式化输出
            this._startime = startime;
            if (startime) {
                this._gettime = typeof (gettime) == "function" ? gettime : Date.now;
                this._startime = this._gettime() ? 0 : startime;
            }
        }
        /**
         * 设置输出的格式(会显示在输出的开头)
         *
         * @param {string} fmtstr
         * @memberof BaseHandler
         */
        BaseHandler.prototype.setFmter = function (fmtstr) {
            this._fmtstr = fmtstr;
        };
        BaseHandler.prototype.emit = function (nlv, sfmt) {
            var sout = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                sout[_i - 2] = arguments[_i];
            }
        };
        BaseHandler.prototype.flush = function () { };
        BaseHandler.prototype.getString = function (nlv, sfmt) {
            if (this._startime) {
                sfmt = "[%d]".format(this._gettime() - this._startime) + sfmt;
            }
            sfmt = "%s[%s]%s".format(this._fmtstr, ne.ELOGLEVEL[nlv], sfmt);
            return sfmt;
        };
        return BaseHandler;
    }());
    ne.BaseHandler = BaseHandler;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var CONSOLE_KEY = {
        50: "error",
        40: "error",
        30: "warn",
        20: "info",
        10: "debug",
        0: "log"
    };
    var SysoutHandler = /** @class */ (function (_super) {
        __extends(SysoutHandler, _super);
        function SysoutHandler(startime, gettime) {
            var _this = _super.call(this, startime, gettime) || this;
            if (true) { //todo native 
                _this._ofunc = _this.web_out;
            }
            return _this;
        }
        SysoutHandler.prototype.web_out = function (nlv, sfmt) {
            var sout = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                sout[_i - 2] = arguments[_i];
            }
            console[CONSOLE_KEY[nlv]].apply(console, __spreadArrays([sfmt], sout[0].slice(0)));
        };
        SysoutHandler.prototype.native_out = function (nlv) {
        };
        SysoutHandler.prototype.emit = function (nlv, sfmt) {
            var sout = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                sout[_i - 2] = arguments[_i];
            }
            var sffmt = this.getString(nlv, sfmt);
            this._ofunc(nlv, sffmt, sout);
        };
        return SysoutHandler;
    }(ne.BaseHandler));
    ne.SysoutHandler = SysoutHandler;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var CONSOLE_KEY = {
        50: "error",
        40: "error",
        30: "warn",
        20: "info",
        10: "debug",
        0: "log"
    };
    var FileHandler = /** @class */ (function (_super) {
        __extends(FileHandler, _super);
        /**
         * Creates an instance of FileHandler.
         * @param {string} filepath
         * @param {string} [mode='w+b']
         * @param {boolean} autoflush
         * @param {number} [startime]
         * @param {Function} [gettime]
         * @memberof FileHandler
         */
        function FileHandler(filepath, mode, autoflush, startime, gettime) {
            if (mode === void 0) { mode = 'w+b'; }
            return _super.call(this, startime, gettime) || this;
            //todo
        }
        FileHandler.prototype.emit = function (nlv, sfmt) {
            var sout = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                sout[_i - 2] = arguments[_i];
            }
        };
        return FileHandler;
    }(ne.BaseHandler));
    ne.FileHandler = FileHandler;
})(ne || (ne = {}));
var ne;
(function (ne) {
    var Event_ = /** @class */ (function () {
        function Event_(name, listener, target, once) {
            this.name = name;
            this.listener = listener;
            this.target = target;
            this.once = once ? once : false;
        }
        return Event_;
    }());
    var EventDispatcher = /** @class */ (function () {
        function EventDispatcher() {
            this._flag = 0; /**防止修改纠错flag */
            this._eventMap = new Map();
        }
        EventDispatcher.prototype.on = function (eventname, listencb, target, once) {
            var eventMap = this._eventMap;
            if (typeof (eventname) == "number") {
                eventname = "MSG_" + eventname;
            }
            var name = eventname;
            var list = eventMap[name];
            if (!list) {
                list = eventMap[name] = [];
            }
            else if (this._flag !== 0) {
                eventMap[name] = list = list.concat();
            }
            this.insertEvent(list, name, listencb, target, once);
        };
        EventDispatcher.prototype.insertEvent = function (list, name, listener, target, once) {
            var length = list.length;
            for (var i = 0; i < length; i++) {
                var event_1 = list[i];
                if (event_1.listener == listener && event_1.target == target) {
                    return false;
                }
            }
            var event = new Event_(name, listener, target, once);
            list.push(event);
        };
        EventDispatcher.prototype.emit = function (eventname) {
            var _a;
            var args = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                args[_i - 1] = arguments[_i];
            }
            if (typeof (eventname) == "number") {
                eventname = "MSG_" + eventname;
            }
            var eventMap = this._eventMap;
            var name = eventname;
            var list = eventMap[name];
            if (!list) {
                return true;
            }
            var length = list.length;
            if (length == 0) {
                return true;
            }
            var onceList = [];
            this._flag++;
            for (var i = 0; i < length; i++) {
                var event_2 = list[i];
                (_a = event_2.listener).call.apply(_a, __spreadArrays([event_2.target], args));
                if (event_2.once) {
                    onceList.push(event_2);
                }
            }
            this._flag--;
            while (onceList.length) {
                var event_3 = onceList.pop();
                this.removeEventListener(event_3.name, event_3.listener, event_3.target);
            }
        };
        EventDispatcher.prototype.removeEventListener = function (name, listener, target) {
            if (typeof (name) == "number") {
                name = "MSG_" + name;
            }
            var eventMap = this._eventMap;
            var list = eventMap[name];
            if (!list) {
                return;
            }
            if (this._flag !== 0) {
                eventMap[name] = list = list.concat();
            }
            this.removeEvent(list, listener, target);
            if (list.length == 0) {
                eventMap[name] = null;
            }
        };
        EventDispatcher.prototype.removeEventListeners = function (name) {
            if (typeof (name) == "number") {
                name = "MSG_" + name;
            }
            var eventMap = this._eventMap;
            var list = eventMap[name];
            if (!list) {
                return;
            }
            list.length = 0;
            eventMap.delete(name);
        };
        EventDispatcher.prototype.removeEvent = function (list, listener, target) {
            var length = list.length;
            for (var i = 0; i < length; i++) {
                var event_4 = list[i];
                if (event_4.listener == listener && event_4.target == target) {
                    list.splice(i, 1);
                    return true;
                }
            }
            return false;
        };
        EventDispatcher.prototype.once = function (eventname, listencb, target) {
            this.on(eventname, listencb, target, true);
        };
        EventDispatcher.prototype.dump = function () {
            var eventMap = this._eventMap;
            for (var name_1 in eventMap) {
                console.log(eventMap[name_1]);
            }
        };
        return EventDispatcher;
    }());
    ne.EventDispatcher = EventDispatcher;
})(ne || (ne = {}));
var ne;
(function (ne) {
    window['ne'] = ne;
})(ne || (ne = {}));
